package com.chinasofti.demo;

import java.sql.*;

public class JDBCDemo01 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //引入依赖(导入jar包)
        //注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //获取连接
        Connection con =
                DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/db14", "root", "123");
        //获取执行对象
        Statement stat =  con.createStatement();

        //执行sql语句
        String sql = "SELECT * FROM student";
        ResultSet rs = stat.executeQuery(sql);

        //处理结果
        while(rs.next()){
            System.out.println(rs.getInt("sid") +"\t"+ rs.getString("name"));
        }
        rs.close();
        stat.close();
        con.close();


    }
}